import request from '@/utils/request'

// 获取爬虫文章列表
export function getCrawlerArticles(params) {
    return request({
        url: 'crawler/article/articles',
        method: 'get',
        params
    })
}

// 删除爬虫文章
export function deleteCrawlerArticle(id) {
    return request({
        url: `crawler/article/articles/${id}`,
        method: 'delete'
    })
}

// 发布爬虫文章
export function publishCrawlerArticle(id, data) {
    return request({
        url: `crawler/article/${id}/status`,
        method: 'put',
        data
    })
}

export function toggleArticleTop(id, isTop, topOrder) {
    return request({
        url: `crawler/article/${id}/top`,
        method: 'put',
        params: {
            isTop,
            topOrder: isTop ? (topOrder || 0) : undefined // 如果是取消置顶，不传权重值
        }
    })
}

export function toggleArticleHot(id, isHot, hotOrder) {
    return request({
        url: `crawler/article/${id}/hot`,
        method: 'put',
        params: {
            isHot,
            hotOrder: isHot ? (hotOrder || 0) : undefined
        }
    })
}

export function toggleArticleRecommend(id, isRecommend, recommendOrder) {
    return request({
        url: `crawler/article/${id}/recommend`,
        method: 'put',
        params: {
            isRecommend,
            recommendOrder: isRecommend ? (recommendOrder || 0) : undefined
        }
    })
}

export function updateArticlesSource(data) {
    return request({
        url: `crawler/article/batch/source`,
        method: 'put',
        data
    })
}

export function updateArticlesStatus(data) {
    return request({
        url: `crawler/article/batch/status`,
        method: 'put',
        data
    })
}

export function batchRemove(ids) {
    return request({
        url: `crawler/article/batch`,
        method: 'delete',
        data: { ids }
    })
}

export function batchArticlesTop(data) {
    return request({
        url: `crawler/article//batch/top`,
        method: 'put',
        data
    })
}

export function batchArticlesHot(data) {
    return request({
        url: `crawler/article/batch/hot`,
        method: 'put',
        data
    })
}

export function batchArticlesRecommend(data) {
    return request({
        url: `crawler/article/batch/recommend`,
        method: 'put',
        data
    })
}

// 获取爬取的图片列表
export function getCrawlerImages(params) {
    return request({
        url: 'crawler/article/images',
        method: 'get',
        params
    })
}

// 删除爬取的图片
export function deleteCrawlerImage(id) {
    return request({
        url: `crawler/article/images/${id}`,
        method: 'delete'
    })
}

// 获取爬虫规则列表
export function getCrawlerRules() {
    return request({
        url: 'crawler/crawler/rules',
        method: 'get'
    })
}

// 创建爬虫任务
export function createCustomCrawlerTask(data) {
    return request({
        url: 'crawler/crawler/tasks',
        method: 'post',
        data
    })
}

// 获取爬虫任务列表
export function getCrawlerTasks(params) {
    return request({
        url: 'crawler/crawler/tasks',
        method: 'get',
        params
    })
}

// 停止爬虫任务
export function stopCrawlerTasks(taskId) {
    return request({
        url: `crawler/crawler/tasks/${taskId}`,
        method: 'delete'
    })
}

// 删除爬虫任务
export function deleteCrawlerTask(taskId) {
    return request({
        url: `crawler/crawler/deleteTask/${taskId}`,
        method: 'delete'
    })
}